#include<bits/stdc++.h>
using namespace std;

const long long N = 1e5+900;
long long t,n,m,lm,vm;
long long d[N],v[N],a[N],p[N];
long long ans;
long long maxx,pf,pf2;
long long xyn,xcy,wz;

long long f(long long j){
    for(int i=1;i<=m;i++){
        if(j<=p[i]){
            return i;
        }
    }
    return lm;
}

int main(){

    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin >> t;

    while(t--){
        ans = 0;xcy = 0;xyn=0;
        cin >> n >> m >> lm >> vm;
        for(int i=1;i<=n;i++){
            cin >>d[i]>>v[i]>>a[i];
        }
        for(int i=1;i<=m;i++){
            cin >>p[i];
        }
        maxx = p[m];
        for(int i=1;i<=n;i++){

            if(a[i]==0){
                xcy++;
                if(v[i]>vm){
                    if(maxx >= d[i]){
                        ans++;
                    }
                }
            }


            if(a[i]>0){
                xcy++;
                if(v[i]>vm){
                    if(maxx >= d[i]){
                        ans++;
                    }
                }
                else{
                    pf2 = vm*vm;
                    pf = v[i]*v[i];
                    if(2*a[i]*(p[m]-d[i])+pf>pf2){
                        ans++;
                    }
                }

            }



            if(a[i]<0){

                if(v[i]>vm){

                    pf2 = vm*vm;
                    pf = v[i]*v[i];
                    wz = f(d[i]);
                    if(wz!=lm){
                        xyn++;
                        if(2*a[i]*(p[wz]-d[i])+pf>pf2){
                                ans++;
                        }
                    }
                }
            }


        }
        cout << ans << " ";
        if(xcy == n){
            if(ans == 0){
                cout << m << endl;
            }
            if(ans != 0){
                cout << m - 1<< endl;
            }
        }
        else{
            cout << m-xyn<<endl;
        }

    }



    return 0;
}
